"use strict";

var backg, activeDomain = "";

function cmdToggleActiveWebsite() {
    if ("" !== activeDomain) {
        backg.toggleActiveWebsite(activeDomain);
        window.close();
    }
}

function cmdOpenOptions() {
    $.openOptionsPage();
    window.close();
}

function cmdOpenContact() {
    $.tab.open("https://dev.tekin.cn/contactus.html?referrer-ver=Block-Yourself-from-Analytics-v" + $.extensionVersion + "-in-" + $.browserSlug);
    window.close();
}

function cmdCloseMenu() {
    window.close();
}

function cmdOpenChangeLog() {
    backg.extensionUpdatedShowChangeLog();
    document.body.className.replace("extension-updated", "");
}

window.addEventListener("DOMContentLoaded", function() {
    $.isBrowserSupported ? $.getBackgroundAsync(function(backgroundPage) {
        if (backg = backgroundPage) {
            backg.isExtensionUpdated && (document.body.className = "menu-hide extension-updated");
            $("cmd_open_options").addEventListener("click", cmdOpenOptions, !1);
            $("cmd_open_contact").addEventListener("click", cmdOpenContact, !1);
            $("cmd_open_changelog").addEventListener("click", cmdOpenChangeLog, !1);
            if (backg.showPopupMenuClose) {
                $("cmd_close_menu").style.display = "block";
                $("cmd_close_menu").addEventListener("click", cmdCloseMenu, !1);
            }
            chrome.tabs.query({
                currentWindow: !0,
                active: !0
            }, function(tabs) {
                var tab = tabs[0];
                if (void 0 !== tab.url && 0 === tab.url.indexOf("http")) {
                    activeDomain = $.domainFromURL(tab.url);
                    backg.ruleIsEnabled(activeDomain) && ($("cmd_toggle_active_website").className = "mchecked");
                    $("cmd_toggle_active_website").title = "Block for: " + activeDomain;
                    $("cmd_toggle_active_website").addEventListener("click", cmdToggleActiveWebsite, !1);
                } else $("cmd_toggle_active_website").className += " mdisabled";
            });
            "menu-hide extension-error" === document.body.className && (document.body.className = "");
        } else {
            if (!chrome.extension.inIncognitoContext) throw new Error("Missing background page");
            document.body.className = "menu-hide extension-incognito";
        }
    }) : document.body.className = "menu-hide extension-support";
}, !1);